import request from "../request"

import axios from 'axios'

/**
 *  在ts的项目里面，有时候会报这种错：无法找到模块“xxx”的声明文件。
 *  原本在一些比较老的 第三方库 在ts项目中使用的时候，就可能会报这个错
 *  之前在这些第三方库有的时候， 还没有ts ，我们在ts项目使用， 就会没有遵守 ts 的规定，提供 声明文件
 *  所以在ts项目中使用 这些第三方库的时候， ts 认为 这些库不合法， 就会报错
 *
 *  但是这些报错是ts的错， js 代码是完全可以运行了
 *  所以这个时候，为了让ts不报错， 需要提供 对应类库的 声明文件
 *  一般来说这些 库都是在 npm 上下载的，所以 也是直接去 npm 找对应的声明库就行
 *  一般来说 ， 第三方库的 额外的声明文件 命名都： @types/第三库
 *  之前我们在配置  vite.config.ts 的时候我们下载了一个  @types/node
 *  所以我们现在解决 ts 报 qs模块 没有声明文件的错 ， 只需要下载  @types/qs
 *  但是不一定所有的 模块 都有 这些补充声明的 库 -- 这种如何解决我们后面再说
 */
import qs from "qs";

// 登录请求
export const LoginAPI = (params: ILoginParams): RSP<ILoginResponse> => request.post('/admin/login', params)

// 获取登录用户信息
export const userInfoApi = (): RSP<IUserInfoResponse> => request.get("/admin/info");

// 用户列表信息请求
// 要注意get请求带参数格式和post请求是不一样的  get请求传的参数是以对象的形式
export const getUserListApi = (params?: IUserListParams): RSP<IUserListData<IUserModel>> => request.get("/admin/list", { params })


/**
 *
 *  在文档里面这么几个单词是可以告诉我们指定 参数的位置
 *
 *    path -->  把参数放友url的里面  /admin/update/{id}
 *    query  --->  把参数放在url的search部分   /id/update?id=xxx&name=xxx
 *    body   --->  post请求把数据放在 请求体里面
 *
 */

// 修改账号状态
export const updateUserStatusApi = (params: IUpdateUserStatusParams): RSP<any> => request.post(`/admin/updateStatus/${params.id}?status=${params.status}`)


// 注册用户接口
export const registerUserApi = (params: IRegisterUserParams): RSP<IUserModel> => request.post("/admin/register", params)

// 根据id获取指定用户的数据
export const getUserInfoApi = (id: number): RSP<IUserModel> => request.get(`/admin/${id}`);


// 修改用户信息
export const updateUserInfoApi = (params: IUserModel): RSP<any> => request.post(`/admin/update/${params.id}`, params)


// 获取所有角色的列表
export const getRoleListApi = (): RSP<IRoleModel[]> => request.get("/role/listAll");


// 获取指定用户的所有的角色
export const getRoleListByAdminIdApi = (adminId: number): RSP<IRoleModel[]> => request.get(`/admin/role/${adminId}`);


// 给指定用户分配角色 - 注意，文档里面要求我们使用的是query形式的参数
// 以前我们用过一个 qs 的模块，可以快速将一个对象转换为  search(query) 形式的参数
// export const updateRolesApi = ({ adminId, roleIds }: IUpdateRolesParams) => {
export const updateRolesApi = (params: IUpdateRolesParams) => {
  // qs 在转换 数组的时候，有点和我们想要的不一样，所以这个东西，我们还是只能自己转换
  // console.log(qs.stringify(params));
  // return request.post(
  //   `/admin/role/update?adminId=${adminId}&roleIds=${roleIds.join(",")}`
  // );

  // qs 模块在转换数组的时候 可以添加一个指定的格式 参数， 让 数组转换成 array=1,2,3,4 的格式
  // console.log(qs.stringify(params, { arrayFormat: "comma" }));
  return request.post(
    //   `/admin/role/update?adminId=${adminId}&roleIds=${roleIds.join(",")}`
    `/admin/role/update?${qs.stringify(params, { arrayFormat: "comma" })}`
  );
};

// 分页获取 角色列表
export const queryRoleListApi = (params: IUserListParams): RSP<IUserListData<IRoleModel>> => request.get("/role/list", { params })

// 获取所有资源的接口
export const getAllResourceApi = (): RSP<IResourceModel[]> => request.get("/resource/listAll");

// 获取所有的资源分类
export const getAllResourceCategoryApi = (): RSP<IResourceCategoryModel[]> => request.get("/resourceCategory/listAll");

// 获取角色相关资源
export const getListRoleResourceApi = (roleId: number): RSP<IResourceModel[]> => request.get(`/role/listResource/${roleId}`);

// 资源分配
export const allocResourceApi = (params: IAllocResourceParams): RSP<any> => request.post("/role/allocResource?" + qs.stringify(params, { arrayFormat: "comma" }));


// 获取菜单列表
export const getMenuListApi = (params: IUserListParams): Promise<IResponse<IMenuListData>> => request.get(`/menu/list/${params.parentId}`, { params })

// 添家菜单接口
export const getMenuAddApi = (params: getMenuAddParams): Promise<IResponse<getMenuAddData>> => request.post(`/mall-admin/menu/create`, params)




//  订单部分的请求接口 ---------------------------------------------------------------------------------------------

// 订单设置
export const getOrderSettingApi = (id: number): RSP<IOrderSettingParams> => request.get(`/orderSetting/${id}`)

// 修改指定订单设置
export const getOrderSettingUpdateApi = (params: IOrderSetting): RSP<{}> => request.post(`/orderSetting/update/${params.id}`, params.orderSetting)

// 分页查询全部退货原因
export const getReturnReasonApi = (params: IReturnReasonPage): RSP<IUserListData<IReturnReasonList>> => request.get(`/returnReason/list`, { params })

// 添加退货原因
export const getCreateReasonApi = (params: IReturnReasonList): RSP<{}> => request.post('/returnReason/create', params)


// 修改用户启用状态
export const getUpdateStatusApi = (params: IUpdateStatus): RSP<{}> => request.post(`/returnReason/update/status?status=${params.status}&ids=${params.ids}`)

// 获取单个退货原因详情
export const getReasonIdApi = (id: number): RSP<IReturnReasonList> => request.get(`/returnReason/${id}`)

// 批量删除    
export const getDeleteReasonApi = (ids: number[]): RSP<{}> => request.post(`/returnReason/delete?ids=${ids}`)

// 修改退货原因---进行编辑 
export const getUpdateReasonApi = (params: IReturnReasonList): RSP<{}> => request.post(`/returnReason/update/${params.id}`, params)


// 退货申请部分 -----------------------------------------------
// 分页查询退货申请   
export const getReturnApplyApi = (params: IReturnApplyParams): RSP<IUserListData<IApplyParamsList>> => request.get(`/returnApply/list`, { params })

// 批量删除退货申请   /returnApply/delete
export const getApplyDeleteApi = (ids: number[]) => request.post(`/returnApply/delete?ids=${ids}`)

// 商品属性管理部分 -----------------------------------------------
// 分页获取 商品属性列表
export const getListProductApi = (params: IUserListParams): RSP<IUserListData<cateModel>> => request.get("/productAttribute/category/list", { params })

//  添加商品属性分类
export const IProductCreateApi = (params: { name: string }): RSP<string> => {
  return request.post(

    "/productAttribute/category/create", qs.stringify(params)
  );
}

// 修改商品属性分类
export const IProductEditApi = (id: number, params: { name: string }): RSP<string> => {
  return request.post(

    `/productAttribute/category/update/${id}`, qs.stringify(params)
  )
}

// 删除商品属性
export const IDelProductApi = (id: number): RSP<string> => request.get(`/productAttribute/category/delete/${id}`)

//获取属性列表和参数列表
export const attriButeListApi = (cid: any, params: getButeList): RSP<IUserListData<AttrListModel>> => request.get(`/productAttribute/list/${cid}`, { params })

// 批量删除属性列表和参数列表
export const delattriButeListApi = (ids: any): RSP<string> => {
  return request.post(
    "/productAttribute/delete", qs.stringify(ids)
  )
}
// 添加商品属性信息
export const attributeParamCreateApi = (param: attributeParamModel): RSP<any> => request.post("/productAttribute/create", param);

// 查询单个商品属性
export const getAttributeApi = (id: any): RSP<attributeParamModel> => request.get(`/productAttribute/${id}`)

// 修改商品属性信息
export const attributeParamEditApi = (id: any, param: attributeParamModel): RSP<string> => request.post(`/productAttribute/update/${id}`, param)




// 商品品牌管理部分------------------
// 获取品牌列表
export const getbrandlistApi = (params?: IUserListParams): RSP<IUserListData<any>> => request.get("/brand/list", { params })
//批量更新厂家制造商状态
export const changefactoryStatusApi = (params: {
  ids: number,
  factoryStatus: number
}): RSP<string> => {
  return request.post(

    "/brand/update/factoryStatus", qs.stringify(params)
  );
}
//批量更新显示状态
export const changeshowStatusApi = (params: {
  ids: number | string,
  showStatus: number
}): RSP<string> => {
  return request.post(

    "/brand/update/showStatus", qs.stringify(params)
  );
}

// 添加商品品牌信息

// export const brandlistCreateApi = (param: brandlistModel): RSP<string> => request.post("/brand/create", param);

export const brandlistCreateApi = (param: brandlistModel): RSP<any> => request.post("/brand/create", param);


// 查询单个品牌属性
export const getBrandlistApi = (id: any): RSP<brandlistModel> => request.get(`/brand/${id}`)

// 修改商品品牌信息

export const brandlistParamEditapi = (id: any, param: brandlistModel): RSP<string> => request.post(`/brand/update/${id}`, param)

// 删除品牌

export const delbrandlistApi = (id: number): RSP<any> => request.get(`/brand/delete/${id}`) //返回data为null


/* ******************************************************************************************* */

///home/advertise/list 广告列表
export const advertiseListApi = (params?: sb): RSP<advertise> => request.get(`/home/advertise/list`, { params })


//广告详情 advertiseList
export const advertiseIDApi = (id: number): RSP<advertiseList> => request.get(`/home/advertise/${id}`)

//修改广告 / home / advertise / update / { id }
export const advertiseUpdate = (params: advertiseUpdateParams) => request.post(`/home/advertise/update/${params.id}`, params.advertise)


//删除广告 / home / advertise / delete
export const advertiseDelete = (params: number[]): RSP<any> => request.post(`/home/advertise/delete?ids=${params}`)


//mall-admin/home/advertise/create 添加
export const advertiseCreate = (params: advertiseList): RSP<any> => request.post('/home/advertise/create', params)


// / mall - admin / home / advertise / update / status / { id }
export const advertiseupdatestatus = (params: advertiseupdatestatusParams): RSP<any> => request.post(`/home/advertise/update/status/${params.id}?status=${params.status}`)


// /home/recommendSubject/list 专题首页
export const recommendSubjectApi = (params: recommendSubjectParams): RSP<IUserListData<recommendSubjectList>> => request.get('/home/recommendSubject/list', { params })


// / mall - admin / subject / list 选择专题
export const subjectListApi = (params: IUserListParams): RSP<IUserListData<subjectListData>> => request.get("/subject/list", { params })


// / mall - admin / home / recommendSubject / create 添加专题
export const recommendSubjectCreateApi = (params: any): RSP<[]> => request.post('/home/recommendSubject/create', params)


// / mall - admin / home / recommendSubject / update / sort / { id }
export const recommendProductupdateApi = (params: recommendProductupdateParams): RSP<[]> => request.post(`/home/recommendSubject/update/sort/${params.id}?sort=${params.sort}&id=${params.id}`)


// / mall - admin / home / recommendSubject / update / recommendStatus 批量修改推荐状态
export const recommendStatusApi = (params: recommendStatusParams): RSP<{}> => request.post(`/home/recommendSubject/update/recommendStatus?ids=${params.ids}&recommendStatus=${params.recommendStatus}`)



export const brandlistParamEditApi = (id: any, param: attributeParamModel): RSP<string> => request.post(`/brand/update/${id}`, param)

// 删除品牌
export const delbrandlistapi = (id: number): RSP<any> => request.get(`/brand/delete/${id}`)


/* *************************************************** */
//秒杀活动列表
export const seckillApi = (params: IUserListParams): RSP<IUserListData<ISkillModel>> => request.get('/flash/list?' + qs.stringify(params, { arrayFormat: "comma" }))

//上线下线
export const selectUpdateApi = (params: IUpdateUserStatusParams): RSP<any> => request.post(`/flash/update/status/${params.id}?status=${params.status}`)

//根据id修改活动信息
export const selectInfoApi = (id: number): RSP<ISkillModel> => request.get(`/flash/${id}`)

//编辑活动信息
export const flashupdateApi = (params: ISkillModel): RSP<any> => request.post(`/flash/update/${params.id}`, params)

//添加活动信息
export const addFlashupdateApi = (params: ISkillModel): RSP<any> => request.post('/flash/create', params)

//删除活动信息
export const flashDleteApi = (id: number): RSP<any> => request.post(`/flash/delete/${id}`)

//设置商品
export const setShopApi = (id: number): RSP<any> => request.get(`/flashSession/selectList?flashPromotionId=${id}`)

//获取秒杀商品列表
export const getShopApi = (params: getShop): RSP<IUserListData<Iproduct>> => request.get(`/flashProductRelation/list?pageNum=${params.pageNum}&pageSize=${params.pageSize}&flashPromotionId=${params.flashPromotionId}&flashPromotionSessionId=${params.flashPromotionSessionId}`)

//秒杀商品列表添加
// export const shoplistApi = (params: IUserListParams): RSP<any> => request.get(`/product/list?pageNum=${params.pageNum}&pageSize=${params.pageSize}`)

//根据商品id获取商品信息
export const shopIDgetApi = (id: number): RSP<any> => request.get(`/productAttribute/${id}`)

//秒杀商品列表添加和查询商品
export const searchApi = (params: IUserListParams): RSP<any> => request.get(`/product/list?keyword=${params.keyword}&pageNum=${params.pageNum}&pageSize=${params.pageSize}`)

//秒杀时间段列表
export const miaoshaTimeApi = (): RSP<ISkillTime[]> => request.get('/flashSession/list')

//秒杀时间段列表编辑获取点击的数据
export const miaoshaTimesetApi = (id: number): RSP<ISkillTime[]> => request.get(`/flashSession/${id}`)
//秒杀时间段列表编辑确认修改
export const miaoshaTimeSuresetApi = (params: ISkillTime): RSP<any> => request.post(`/flashSession/update/${params.id}`, params)
//秒杀时间段列表编辑确认添加
export const miaoshaTimeSureApi = (params: ISkillTime): RSP<any> => request.post('/flashSession/create', params)
//秒杀时间段列表修改启用状态
export const modifystateApi = (params: IUpdateUserStatusParams): RSP<any> => request.post(`/flashSession/update/status/${params.id}?status=${params.status}`)

/* ******************************* */
//获取优惠卷列表
export const getCouponlistApi = (params: couponList): RSP<IUserListData<couponListModel>> => request.get(`/coupon/list?pageNum=${params.pageNum}&pageSize=${params.pageSize}`)





// 张婷的部分
// 商品分类查询的接口
export const productCategoryApi = (
  params: productCategotyList
): RSP<IUproductCategoty> =>
  request.get(`/productCategory/list/${params.parentId}`, { params });

// 修改导航栏按钮的状态
export const updatenavStatusApi = (params: IupdatenavStatus): RSP<any> =>
  request.post(
    `/productCategory/update/navStatus/navStatus=${params.navStatus}`
  );

// 修改显示按钮的状态
export const updatenshowStatusApi = (params: IupdateshowStatus): RSP<any> =>
  request.post(
    "/productCategory/update/showStatus?" +
    qs.stringify(params, { arrayFormat: "comma" })
  );

// 删除商品分类
export const productCategoryDeleteApi = (id: number): RSP<IUproductCategoty> =>
  request.post(`/productCategory/delete/${id}`);

// 根据id获取商品分类
export const EditProductCategory = (
  id: number
): RSP<Ichildren> =>
  request.get(`/productCategory/${id}`);


// 获取所有商品属性和属性
export const productAttributeApi = (): RSP<withAttr[]> => request.get(`/productAttribute/category/list/withAttr`)

// 点击编辑页面的提交按钮修改数据
export const productCategoryUpateApi = (id: any, params: IproductCategoryupdate): RSP<IproductCategoryupdate> => request.post(`/productCategory/update/${id}`, params)

// 添加商品分类
export const productCategorycreateApi = (params: any): RSP<Icreate> => request.post(`/productCategory/create`, params)


// 查询所有的一级分类及分类
export const withChildrenApi = (): RSP<Iwitchildren[]> => request.get(`/productCategory/list/withChildren`)

// 创建商品
export const productcreateApi = (params: any): RSP<ICreates> => request.post(`/product/create`, params)

// 根据品牌名称分页获取品牌列表
export const brandListAPi = (params: Ibrand): RSP<Ibrand> => request.get(`/brand/list?pageNum=${params.pageNum}&pageSize=${params.pageSize}`)

// 商品列表的请求
export const shangpingApi = (params: Ishangpins): RSP<Ishangpins> => request.get(`/product/list?pageNum=${params.pageNum}&pageSize=${params.pageSize}`)

// 批量修改上下架的状态
export const IupdatePulishStatusApi = (params: IupdatePulishStatus): RSP<any> => request.post(`/product/update/publishStatus?ids=${params.id}&publishStatus=${params.publishStatus}`)


// 批量设为新品的状态
export const IupdateNewStatusApi = (params: IupdateNewStatus): RSP<any> => request.post(`/product/update/newStatus?ids=${params.id}&newStatus=${params.newStatus}`)

//  批量推荐新品
export const IupdaterecommendStatusApi = (params: IupdaterecommendStatus): RSP<any> => request.post(`/product/update/recommendStatus?ids=${params.id}&recommendStatus=${params.recommandStatus}`)

// 批量删除
export const IupdateDeletStatusApi = (params: IupdatedeleteStatus): RSP<any> => request.post(`/product/update/deleteStatus?ids=${params.id}&deleteStatus=${params.deleteStatus}`)

// 批量审核修改状态
export const IupdateVerifyStatusApi = (params: IupdateVerifyStatus): RSP<any> => request.post(`  /product/update/verifyStatus?ids=${params.id}&verifyStatus=${params.verifyStatus}`)



// / mall - admin / home / recommendProduct / list 人气 分页查询推荐
export const recommendProductlistApi = (params: recommendProductlistParams): RSP<IUserListData<recommendProductlist>> => request.get('/home/recommendProduct/list', { params })


// / mall - admin / home / recommendProduct / update / sort / { id } 人气修改排序
export const HotupdatesortApi = (params: recommendProductupdateParams): RSP<[]> => request.post(`/home/recommendProduct/update/sort/${params.id}?sort=${params.sort}&id=${params.id}`)

// / mall - admin / home / recommendProduct / update / recommendStatus批量修改人气状态
export const HotupdaterecommendStatus = (params: recommendStatusParams) => request.post(`/home/recommendProduct/update/recommendStatus?ids=${params.ids}&recommendStatus=${params.recommendStatus}`)


// /mall-admin/product/list查询商品
export const productlist = (params: IUserListParams): RSP<IUserListData<productlistData>> => request.get('/product/list', { params })


// / mall - admin / home / recommendProduct / create 添加人气商品
export const Hotcreate = (params: recommendProductlist[]) => request.post('/home/recommendProduct/create', params)



// / mall - admin / home / newProduct / list 新品推荐首页
export const newProductListApi = (params: newProductListParams): RSP<IUserListData<recommendSubjectList>> => request.get('/home/newProduct/list', { params })


// / mall - admin / home / newProduct / update / sort / { id } 新品修改排序
export const newProductupdatesort = (params: recommendProductupdateParams): RSP<[]> => request.post(`/home/newProduct/update/sort/${params.id}?id=${params.id}&sort=${params.sort} `)


// / mall - admin / home / newProduct / update / recommendStatus 新品 批量修改状态
export const newProductupdateApi = (params: recommendStatusParams): RSP<[]> => request.post(`/home/newProduct/update/recommendStatus?ids=${params.ids}&recommendStatus=${params.recommendStatus}`)




// / mall - admin / home / newProduct / create 新品添加
export const newAdd = (params: recommendProductlist[]) => request.post("/home/newProduct/create", params)

/* ********************************************************* */
//获取单个优惠卷信息
export const getConupApi = (id: number): RSP<cupModel> => request.get(`/coupon/${id}`)

//优惠卷列表查询
export const searchConupApi = (params: couponList): RSP<IUserListData<couponListModel>> => request.get(`coupon/list?pageNum=${params.pageNum}&pageSize=${params.pageSize}&name=${params.keyword}&type=${params.type}`)

//优惠码
// /mall-admin/couponHistory/list
export const couponHistoryListApi = (params: couponList): RSP<IUserListData<cupVipModel>> => request.get(`couponHistory/list?pageNum=${params.pageNum}&pageSize=${params.pageSize}&couponId=${params.id}`)

//优惠卷领取查询
export const searchCouponApi = (params: couponList): RSP<IUserListData<cupVipModel>> => request.get(`couponHistory/list?pageNum=${params.pageNum}&pageSize=${params.pageSize}&useStatus=${params.useStatus}&couponId=${params.id}`)



/* ******************** */
// 获取品牌列表
// /mall-admin/home/brand/list
export const getBrandApi = (params: getBrandModel): RSP<IUserListData<getBrandlist>> => request.get(`/home/brand/list?pageNum=${params.pageNum}&pageSize=${params.pageSize}`)
//查询
export const searchBrandApi = (params: getBrandModel): RSP<IUserListData<getBrandlist>> => request.get(`/home/brand/list?pageNum=${params.pageNum}&pageSize=${params.pageSize}&brandName=${params.brandName}&recommendStatus=${params.recommendStatus}`)
//确认设置排序
export const sureSetsortApi = (params: sureSetsortModel): RSP<any> => request.post(`home/brand/update/sort/${params.id}?sort=${params.sort}&id=${params.id}`)

// 获取退货申请详情 
export const getApplyDeatils = (id: number): RSP<IApplyDetailsParams> => request.get(`/returnApply/${id}`)

//获取订单详情：订单信息、商品信息、操作记录    
export const getOrderDetailApi = (id: number): RSP<IOrderParams> => request.get(`/order/${id}`)

